﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Google.GData.Calendar;
using Google.GData.Client;
using Google.GData.Extensions;

namespace GoogleCalendarPluggin
{
    public class GoogleCalendarUtils
    {
        private static string appName = "MyCalendar";
        private static string userName = "louisphilippejette@gmail.com";
        private static string password = "";
        private static Uri calendarUri = new Uri("http://www.google.com/calendar/feeds/" +  userName + "/private/full");


        private CalendarService service = null;

        public GoogleCalendarUtils()
        {
            // connect to the calendar service
            service = new CalendarService(appName);
            service.setUserCredentials(userName, password);

        }

        public void InsertEntry()
        {
            EventEntry entry = new EventEntry();

            entry.Title.Text = "Trying with Seb";

            string htmlDescription = "Woww, really ?";

            if (htmlDescription != null && htmlDescription.Length > 0)
            {
                entry.Content.Type = "html";
                entry.Content.Content = htmlDescription;
            }

           
                Where eventLocation = new Where();
                eventLocation.ValueString = "concordia";
                entry.Locations.Add(eventLocation);



                DateTime start = DateTime.Now;

            When eventTime = new When();
            eventTime.StartTime = start;


            DateTime endTime = DateTime.Now.AddHours(2);
            eventTime.EndTime = endTime;


            entry.Times.Add(eventTime);

     
            eventTime.AllDay = true;
            

            AtomPerson author = new AtomPerson(AtomPersonType.Author);
            author.Name = "Simon Williams";
            author.Email = "simon@kajabity.com";
            entry.Authors.Add(author);

            AtomEntry insertedEntry = service.Insert(calendarUri, entry);

            
        }
    }
}
